<template>
  <div class="classify">
    <ComSearchNav />
    <section>
      <van-tree-select height="100%" :items="classifyLNav" :main-active-index.sync="active" @click-nav="handleClick">
        <template #content>
          <div v-if="active === 0">
            <p>热门大牌推荐</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" @click="handleItem(item)">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
          </div>
          <div v-if="active === 1">
            <p>鞋靴品牌大全</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
            <!-- <p>运动品牌大全</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid> -->
          </div>
          <div v-if="active === 2">
            <p>热门品牌</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
            <!-- <p>极简实穿</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid> -->
          </div>
          <div v-if="active === 3">
            <p>热门品牌</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
          </div>
          <div v-if="active === 4">
            <p>热门品牌</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
          </div>
          <div v-if="active === 5">
            <p>户外服装</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
          </div>
          <div v-if="active === 6">
            <p>童鞋</p>
            <van-grid :column-num="3">
              <van-grid-item v-for="item in listItems0" :key="item.id" to="/goodsList">
                <img :src="item.img">
                <span>{{item.name}}</span>
              </van-grid-item>
            </van-grid>
          </div>
        </template>
      </van-tree-select>
    </section>
  </div>
</template>

<script>
import ComSearchNav from "../components/comSearchNav";
import { classifyList, classifyContent } from "../utils/classify";
// import ClassifyRWarp from "../components/classifyRWarp";
import axios from "axios";
export default {
  name: "Classify",
  data() {
    return {
      active: 0,
      classifyLNav: [
        { text: "大牌推荐" },
        { text: "全部品牌" },
        { text: "女鞋" },
        { text: "男鞋" },
        { text: "运动" },
        { text: "户外" },
        { text: "童鞋童装" }
      ],
      listItems0: []
    };
  },
  mounted() {
    // console.log(this.$router);//vue-router对象里的routes数组里的每项配置
    classifyList().then(res => {
      res.forEach(item => {
        item.text = item.tname;
      });
      this.classifyLNav = res;
      let params = {
        tid: 1
      };
      classifyContent(params).then(res => {
        console.log(res);
        let arr = [];
        res.forEach(item => {
          arr.push({ name: item.bname, img: item.logo, bid: item.bid,picture: item.picture });
        });
        this.listItems0 = arr;
      });
    });
  },
  methods: {
    handleItem(item) {
      console.log(item.picture,item)
      localStorage.setItem("brandBgc", item.picture);
      this.$router.push({
        path: "/goodsList",
        query: { bid: item.bid }
      });
    },
    handleClick(index) {
      let params = {
        tid: index + 1
      };
      classifyContent(params).then(res => {
        console.log(res);
        let arr = [];
        res.forEach(item => {
          arr.push({
            name: item.bname,
            img: item.logo,
            bid: item.bid,
            picture: item.picture
          });
        });
        this.listItems0 = arr;
      });
    }
  },
  components: {
    ComSearchNav
    // ClassifyRWarp,
  }
};
</script>

<style lang="scss" scoped>
.classify {
  width: 100%;
  height: 100vh;
  section {
    width: 100%;
    height: 100%;
    ::v-deep .van-tree-select {
      .van-sidebar {
        width: 90px;
        height: 100%;
        background-color: #fff;
      }
      .van-tree-select__nav {
        width: 90px;
        flex: inherit;
      }
      .van-sidebar-item--select::before {
        width: 0;
      }
      .van-sidebar-item {
        color: #666;
        background-color: #fff;
        width: 90px;
        height: 42px;
        line-height: 42px;
        text-align: center;
        padding: 0;
        border-bottom: 1px solid #ddd;
      }
      .van-sidebar-item--select,
      .van-sidebar-item--select:active {
        background-color: #eee;
        color: red;
      }
    }
    .van-tree-select__content {
      background-color: #eee;
      width: 100%;
      p {
        height: 50px;
        color: #333;
        font-size: 16px;
        line-height: 40px;
        padding-top: 10px;
        box-sizing: border-box;
        text-align: center;
      }
      .van-grid {
        width: 96%;
        height: 100%;
        margin: 0 auto;
        .van-grid-item {
          height: 108px;
          border: 0;
          img {
            width: 55px;
            padding: 0 0 10px;
            display: block;
            margin: 0 auto;
            min-height: 47px;
          }
          span {
            font-size: 14px;
            color: #333;
          }
        }
      }
    }
  }
}
</style>